package gui;

import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableRowSorter;

import util.MainMouseListener;
import data.EVEItem;
import data.EVESystem;
import data.ItemSystemCollection;

public class ProductGroupSplitPane extends JSplitPane {

  private ItemSystemCollection _collection;
  private ItemList             _itemList;
  private SystemList           _systemList;

  public ProductGroupSplitPane(ItemSystemCollection collection, MainMouseListener mouseListener) {
    super();

    _collection = collection;

    _itemList = new ItemList(_collection);
    _itemList.addMouseListener(mouseListener);
    _systemList = new SystemList(_collection);
    _systemList.addMouseListener(mouseListener);

    for (EVEItem item : _collection.getItems()) {
      _itemList.addItem(item);
    }

    for (EVESystem system : _collection.getSystems()) {
      _systemList.addSystem(system);
    }

    setOrientation(JSplitPane.VERTICAL_SPLIT);

    JScrollPane systemListPane = new JScrollPane(_systemList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    JScrollPane itemListPane = new JScrollPane(_itemList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    setTopComponent(itemListPane);
    setBottomComponent(systemListPane);
    setResizeWeight(0.5);
  }

  public void addSystem(EVESystem newSystem) {
    _collection.addSystem(newSystem);
    _systemList.addSystem(newSystem);
  }

  public void addItem(EVEItem newItem) {
    _collection.addItem(newItem);
    _itemList.addItem(newItem);
  }

  public ItemList getItemList() {
    return _itemList;
  }

  public SystemList getSystemList() {
    return _systemList;
  }
  
  public ItemSystemCollection getCollection() {
    return _collection;
  }
}
